﻿using System;
using OdaOperation.Core.Parameters;
using OdaOperation.DB;
using OdaOperation.Model;

namespace OdaOperation.Core.Creators
{
    public static class TableLabelCreateExtend
    {
        /// <summary>
        /// 创建表格标签的工厂方法，根据给定参数返回 TableLabelCreator 实例
        /// </summary>
        /// <param name="db"></param>
        /// <param name="layerName"></param>
        /// <param name="tableSize"></param>
        /// <param name="angle"></param>
        /// <param name="length1"></param>
        /// <param name="length2"></param>
        /// <param name="fontSize"></param>
        /// <param name="font"></param>
        /// <returns></returns>
        public static TableLabelCreator TableLabelFactory(this DbDatabase db, string layerName, TableSize tableSize, double angle = Math.PI / 4.0, double length1 = 40.0, double length2 = 20.0, double fontSize = 12.0, string font = "F-HZTXT")
        {
            return new TableLabelCreator(db.Database, layerName, tableSize, angle = Math.PI / 4.0, length1 = 40.0, length2, fontSize, font);
        }

        /// <summary>
        /// 创建表格标签的工厂方法，根据给定参数返回 TableLabelCreator 实例
        /// </summary>
        /// <param name="db"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public static TableLabelCreator TableLabelFactory(this DbDatabase db, TableLabelParameter parameter)
        {
            return new TableLabelCreator(db.Database).SetParameter(parameter);
        }

        /// <summary>
        /// 在数据库中追加表格标签
        /// </summary>
        /// <param name="db"></param>
        /// <param name="layerName"></param>
        /// <param name="blockName"></param>
        /// <param name="tables"></param>
        /// <param name="tableSize"></param>
        /// <param name="angle"></param>
        /// <param name="length1"></param>
        /// <param name="length2"></param>
        /// <param name="fontSize"></param>
        /// <param name="font"></param>
        public static void AppendOdDbTableLabel(this DbDatabase db, string layerName, string blockName, TableData tables, TableSize tableSize, double angle = Math.PI / 4.0, double length1 = 40.0, double length2 = 20.0, double fontSize = 12.0, string font = "F-HZTXT")
        {
            // 创建表格标签的参数对象
            TableLabelParameter parameter = new TableLabelParameter
            {
                LayerName = layerName,
                BlockName = blockName,
                TableData = tables,
                TableSize = tableSize,
                Angle = angle,
                Length1 = length1,
                Length2 = length2,
                FontStyle = font,
                FontSize = fontSize
            };
            // 创建并添加表格标签
            new TableLabelCreator(db.Database).SetParameter(parameter).Create();
        }

        /// <summary>
        /// 在数据库中追加表格标签
        /// </summary>
        /// <param name="db"></param>
        /// <param name="parameter"></param>
        public static void AppendOdDbTableLabel(this DbDatabase db, TableLabelParameter parameter)
        {
            // 创建并添加表格标签
            new TableLabelCreator(db.Database).SetParameter(parameter).Create();
        }
    }

}